#include "StdAfx.h"
#include "NeuronTrainerGHA.h"
#include <vector>

using namespace std;

NeuronTrainerGHA::NeuronTrainerGHA(float learnignRate)throw(IllegalArgumentException)
{
	if (learnignRate<=0.0){
		throw IllegalArgumentException("Neuron Class, learning rate is zero");
	}
	_lerningRate = learnignRate;
}


NeuronTrainerGHA::~NeuronTrainerGHA(void)
{
}



vector<vector<float>> NeuronTrainerGHA::calculateWeights(vector<Neuron *> neuronsList,vector<float> values)
{
	vector<float> outputs;
	float sum=0;
	vector<vector<float>>weights;
	outputs.resize(neuronsList.size());
	weights.resize(neuronsList.size());

	for (unsigned int j=0;j<neuronsList.size();j++){
		neuronsList[j]->setInputsValues(values);
		neuronsList[j]->calculateOutput();
	}

	for (unsigned int j=0;j<neuronsList.size();j++){
		for (unsigned int i=0;i<values.size();i++){
			sum = calculateSummary(neuronsList,i,j);
			float weight=_lerningRate*outputs[j]*(values[i]-sum);
			weights[j][i] += weight;
		}

		neuronsList[j]->setInputsWeights(weights[j]);
	}
		
	return weights;
}

float NeuronTrainerGHA::calculateSummary(vector<Neuron *> neuronsList,int i, int j)
{
	float sum=0;
	for (int k=0;k<=j;k++){
		//float weight=weights[k][i];
		//float out=output[k];
		//sum+=weight*out;
	}

	return sum;
}
